package cn.tedu.epidemic.webapi.service.impl;

import cn.tedu.community.commons.excepion.ServiceException;
import cn.tedu.community.commons.pojo.commodity.dto.CommodityDTO;
import cn.tedu.community.commons.pojo.commodity.vo.CommodityListVO;
import cn.tedu.community.commons.pojo.commodity.vo.CommodityStandardByIdVO;
import cn.tedu.community.commons.restful.ServiceCode;
import cn.tedu.epidemic.service.CommodityService;
import cn.tedu.epidemic.webapi.mapper.CommodityMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CommodityServiceImpl implements CommodityService {
     @Autowired
     private CommodityMapper mapper;

    @Override
    public void insert(CommodityDTO commodityDTO) {
        int rows = mapper.insert(commodityDTO);
        log.debug("受影响的行数，参数：{}",rows);
    }

    @Override
    public List<CommodityListVO> list() {
       List<CommodityListVO> list= mapper.list();
       for(CommodityListVO item:list){
           log.debug("{}",item);
       }
       return list;
    }

    @Override
    public CommodityStandardByIdVO getStandardById(int id) {
        log.debug("根据用户id开始处理【查询代买】详情信息，{}",id);
        CommodityStandardByIdVO commodityStandardByIdVO = mapper.getStandardById(id);
        if(commodityStandardByIdVO==null){
            String message="查询代买信息失败，尝试访问数据不存在!";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERR_NOTFOUND,message);
        }
        log.debug("即将访问的数据，参数：{}",commodityStandardByIdVO);
        return commodityStandardByIdVO;
    }
}
